package com.xinya.wanandroidclient.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.xinya.wanandroidclient.bean.HomeBannerBean
import com.youth.banner.adapter.BannerAdapter


/**
 *
 * @ClassName:      HomeBannerAdapter$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/2/25$ 19:23$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class HomeBannerAdapter(dataList: MutableList<HomeBannerBean>?) :
    BannerAdapter<HomeBannerBean, HomeBannerAdapter.BannerViewHolder>(dataList) {

    class BannerViewHolder(itemView: ImageView) : RecyclerView.ViewHolder(itemView) {
        val imageView: ImageView = itemView
    }

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent?.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder?,
        data: HomeBannerBean?,
        position: Int,
        size: Int
    ) {
        Glide.with(holder!!.imageView.context).load(data!!.imagePath).into(holder.imageView)
    }
}